package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.limao.DBDataClass.SysVersionDataClass;
import com.limao.DbConnection.DbConnectionManager;

public class CrowdVersonProvider {
	
	private static class DB_verson_ProviderContainer {
		private static CrowdVersonProvider instance = new CrowdVersonProvider();
	}

	public static CrowdVersonProvider getInstance() {
		return DB_verson_ProviderContainer.instance;
	}

	// 定义系统表的name与操作语句
	// wawa_mobile_code 手机验证码
	private static final String table = "cd_sys_verson";
	private static final String LOAD_VERSON_ByName = "SELECT * FROM " + table+" where name=?";

	// 初始化
	private CrowdVersonProvider() {

	}

	// 某个客户端的版本
	public SysVersionDataClass Load_VersonByName(String name) 
	{
		SysVersionDataClass tmp=null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement(LOAD_VERSON_ByName); // load
			pstmt.setString(1, name);
			rs = pstmt.executeQuery();
			if (rs.next()) {
				tmp = new SysVersionDataClass();
				tmp.name = rs.getString("name");					// 客户端名称
				tmp.verson = rs.getString("verson");				// 版本号
				tmp.updatetime = rs.getLong("updatetime") + "";		// 发布更新时间
				tmp.downloadurl = rs.getString("downloadurl");		// 客户端下载地址
				tmp.message = rs.getString("message");				// 版本跟新提示语
				tmp.state = rs.getString("state");					// 是否强制更新 (0: 否, 1: 是)
			}

		} catch (Exception e) {
			tmp=null;
			e.printStackTrace();
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return tmp;
		
	}
}
